package com.yidi.system.repository;

import com.yidi.common.core.Repository.BaseRepository;
import com.yidi.common.core.domain.entity.SysDictData;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author ：Xn
 * @ClassName: SysDictDataRepository
 * @date ：2021-10-19 14:41
 * @describe ：字典数据
 */
@Repository
public interface SysDictDataRepository extends BaseRepository<SysDictData,Long> {

    List<SysDictData> findByDictTypes(String dictType);

    @Modifying
    @Transactional
    @Query("update SysDictData set dictTypes = ?1 where dictTypes = ?2")
    void updateDictDataType(String newDictTypeString, String oldDictTypeString);

    @Query("from SysDictData dd where dd.dictTypes = ?1 and dd.status = 0 and dd.removeStatus =0")
    List<SysDictData> selectDictDataByType(String dictType);

    @Query(nativeQuery = true, value = "select count(1) from sys_dict_data dd where dd.dict_type = ?1 and dd.remove_status = '0'")
    Integer countDictDataByType(String dictType);
}
